package com.ljk.study6ormtkmybatispage.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ljk.study6ormtkmybatispage.entity.User;
import com.ljk.study6ormtkmybatispage.mapper.UserMapper;
import com.ljk.study6ormtkmybatispage.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;


import javax.annotation.Resource;
import java.util.List;

/**
 * desc:
 *
 * @author ljk
 * @date 2021/4/2 22:01
 */
@Service
public class UserServiceImpl implements UserService {
    @Resource
    private UserMapper userMapper;


    @Override
    public List<User> findUserByName(String name) {
        Example example = new Example(User.class);
        example.createCriteria().andEqualTo("name",name);
        List<User> users = userMapper.selectByExample(example);
        return users;
    }

    @Override
    public PageInfo<User> findAllUserPage(int pageSize, int pageNum) {
        PageHelper.startPage(pageNum, pageSize).setOrderBy("id asc");
        PageInfo<User> userPageInfo = new PageInfo<>(this.userMapper.selectAll());
        return userPageInfo;
    }
}
